package 刷题.leedcode22;
//链表中倒数第k个结点
public class Solution1 {
    public ListNode FindKthToTail(ListNode head,int k){
        int size = 0;
        int right = 0;
        ListNode cur = head;
        //链表为空的情况
        if(head == null){
            return null;
        }
        //计算链表长度
        while(cur != null){
            ++size;
            cur = cur.next;
        }
        //k大于长度的情况
        if(size < k){
            return null;
        }
        while(right < size  - k){
            head = head.next;
            right ++;
        }
        return head;
    }
}
